import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '图片',
    align: 'center',
    dataIndex: 'pic',
    width: 100,
    customRender({value}) {
        return render.renderImage(value);
    },
  },
  {
    title: '商品名称',
    align: 'center',
    dataIndex: 'prodName',
    width: '400px',
  },
  {
    title: '简介',
    align: 'center',
    dataIndex: 'brief',
    width: '400px',
  },
  {
    title: '分类',
    align: 'center',
    dataIndex: 'prodCategory_dictText',
    width: 100,
  },
  {
    title: '配送方式',
    align: 'center',
    dataIndex: 'deliveryMode_dictText',
    width: 100,
  },
  {
    title: '原价',
    align: 'center',
    dataIndex: 'oriPrice',
    width: 60,
  },
  {
    title: '现价',
    align: 'center',
    dataIndex: 'price',
    width: 60,
  },
  {
    title: '销量',
    align: 'center',
    dataIndex: 'soldNum',
    width: 60,
  },
  {
    title: '总库存',
    align: 'center',
    dataIndex: 'totalStocks',
    width: 60,
  },
  {
    title: '条形码',
    align: 'center',
    dataIndex: 'barCode',
    width: 100,
  },
  {
    title: '新品',
    align: 'center',
    dataIndex: 'news',
    width: 60,
    customRender: ({ value }) => {
      if (value == 1) {
        return '是';
      }
      return '否';
    },
  },
  {
    title: '热销',
    align: 'center',
    dataIndex: 'hot',
    width: 60,
    customRender: ({ value }) => {
      if (value == 1) {
        return '是';
      }
      return '否';
    },
  },
  {
    title: '推荐',
    align: 'center',
    dataIndex: 'recommend',
    width: 60,
    customRender: ({ value }) => {
      if (value == 1) {
        return '是';
      }
      return '否';
    },
  },
  {
    title: '首页展示',
    align: 'center',
    dataIndex: 'home',
    width: 80,
    customRender: ({ value }) => {
      if (value == 1) {
        return '是';
      }
      return '否';
    },
  },
  {
    title: '固定运费',
    align: 'center',
    width: 80,
    dataIndex: 'freightAmount',
  },
  {
    title: '状态',
    align: 'center',
    width: 60,
    dataIndex: 'status_dictText',
  },
  {
    title: '上架时间',
    align: 'center',
    dataIndex: 'putawayTime',
    width: 160,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '商品名称',
    field: 'prodName',
    component: 'JInput',
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'goods_status',
    },
  },
  {
    label: '商品分类',
    field: 'prodCategory',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'uf_mall_goods_category,category_name,id',
      pidField: 'parent_category',
    },
  },
  {
    label: '商品条码',
    field: 'barCode',
    component: 'JInput',
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '主图',
    field: 'pic',
    component: 'JImageUpload',
    required: true,
    colProps: {
      span: 6,
    },
  },
  {
    label: '轮播图',
    field: 'imgs',
    component: 'JImageUpload',
    required: true,
    colProps: {
      span: 12,
    },
    componentProps: {
      fileMax: 5,
    },
  },
  {
    label: '商品名称',
    field: 'prodName',
    component: 'Input',
    required: true,
  },
  {
    label: '简介',
    field: 'brief',
    component: 'Input',
  },
  {
    label: '配送方式',
    field: 'deliveryMode',
    component: 'JDictSelectTag',
    required: true,
    componentProps: {
      dictCode: 'delivery_type',
    },
  },
  {
    label: '原价',
    field: 'oriPrice',
    component: 'InputNumber',
    colProps: {
      span: 10,
    },
    required: true,
  },
  {
    label: '现价',
    field: 'price',
    component: 'InputNumber',
    colProps: {
      span: 10,
    },
    required: true,
  },
  {
    label: '销量',
    field: 'soldNum',
    component: 'InputNumber',
    colProps: {
      span: 10,
    },
    required: true,
  },
  {
    label: '运费类型',
    field: 'freightType',
    component: 'JDictSelectTag',
    colProps: {
      span: 10,
    },
    defaultValue: 'FIXED',
    required: true,
    componentProps: {
      dictCode: 'freight_type',
    },
  },
  {
    label: '运费',
    field: 'freightAmount',
    component: 'InputNumber',
    colProps: {
      span: 10,
    },
    defaultValue: '0',
    required: true,
  },
  {
    label: '运费模板',
    field: 'freightTemplate',
    component: 'JSearchSelect',
    colProps: {
      span: 10,
    },
    required: true,
    componentProps: {
      dict: 'uf_mall_freight_template,template_name,id,del_flag=0',
    },
  },
  {
    label: '商品分类',
    field: 'prodCategory',
    component: 'JTreeSelect',
    colProps: {
      span: 10,
    },
    componentProps: {
      dict: 'uf_mall_goods_category,category_name,id',
      pidField: 'parent_category',
    },
  },
  {
    label: '商品条码',
    field: 'barCode',
    component: 'Input',
    colProps: {
      span: 10,
    },
  },
  // {
  //   label: '商品分类',
  //   field: 'prodCategory',
  //   component: 'Input',
  // },
  {
    label: '新品',
    field: 'news',
    component: 'RadioButtonGroup',
    defaultValue: '0',
    componentProps: {
      options: [
        { label: '否', value: 0 },
        { label: '是', value: 1 },
      ],
    },
    colProps: {
      span: 6,
    },
  },
  {
    label: '热销',
    field: 'hot',
    component: 'RadioButtonGroup',
    defaultValue: '0',
    componentProps: {
      options: [
        { label: '否', value: 0 },
        { label: '是', value: 1 },
      ],
    },
    colProps: {
      span: 4,
    },
    labelWidth: '50px',
  },
  {
    label: '推荐',
    field: 'recommend',
    component: 'RadioButtonGroup',
    defaultValue: '0',
    componentProps: {
      options: [
        { label: '否', value: 0 },
        { label: '是', value: 1 },
      ],
    },
    colProps: {
      span: 4,
    },
    labelWidth: '50px',
  },
  {
    label: '首页展示',
    field: 'home',
    component: 'RadioButtonGroup',
    defaultValue: '0',
    componentProps: {
      options: [
        { label: '否', value: 0 },
        { label: '是', value: 1 },
      ],
    },
    colProps: {
      span: 5,
    },
    labelWidth: '80px',
  },
  {
    label: '商品介绍',
    field: 'content',
    component: 'JEditor',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  prodName: { title: '商品名称', order: 0, view: 'text', type: 'string' },
  brief: { title: '简介', order: 1, view: 'text', type: 'string' },
  putawayTime: { title: '上架时间', order: 2, view: 'text', type: 'string' },
  version: { title: '版本号', order: 3, view: 'text', type: 'string' },
  supplierId: { title: '所属供应商', order: 4, view: 'text', type: 'string' },
  status: { title: '状态', order: 5, view: 'number', type: 'number' },
  pic: { title: '主图', order: 6, view: 'text', type: 'string' },
  imgs: { title: '轮播图', order: 7, view: 'text', type: 'string' },
  deliveryMode: { title: '配送方式', order: 8, view: 'text', type: 'string' },
  content: { title: '商品介绍', order: 9, view: 'text', type: 'string' },
  oriPrice: { title: '原价', order: 10, view: 'number', type: 'number' },
  price: { title: '现价', order: 11, view: 'number', type: 'number' },
  soldNum: { title: '销量', order: 12, view: 'number', type: 'number' },
  totalStocks: { title: '总库存', order: 13, view: 'text', type: 'string' },
  prodCategory: { title: '商品分类', order: 14, view: 'text', type: 'string' },
  news: { title: '新品', order: 15, view: 'number', type: 'number' },
  hot: { title: '热销', order: 16, view: 'number', type: 'number' },
  recommend: { title: '推荐', order: 17, view: 'number', type: 'number' },
  home: { title: '首页展示', order: 18, view: 'number', type: 'number' },
  freightAmount: { title: '运费', order: 19, view: 'number', type: 'number' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
